package com.zhangdi.mgsync.core.listener;

import com.zhangdi.mgsync.core.cache.Cache;
import com.zhangdi.mgsync.core.cache.CacheManager;
import com.zhangdi.mgsync.core.cache.EhCacheManager;
import com.zhangdi.mgsync.core.common.MgSyncConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

/**
 * Created by zhangdi on 2020/07/15 16:19:40.
 */
public class BaseMessageListener implements ListenerCacheManager {
    protected Logger logger = LoggerFactory.getLogger(BaseMessageListener.class);

    CacheManager cacheManager;

    @Bean
    public CacheManager cacheManager(){
        cacheManager = new EhCacheManager();
        return cacheManager;
    }

    private Cache<String, String> token_cache;

    @Override
    public Cache<String, String> getCacheManager() {
        if (null == token_cache) {
            token_cache = cacheManager.getCache(MgSyncConst.CACHE_NAME);
        }
        return token_cache;
    }

    @Override
    public void setCacheManager(CacheManager cacheManager) {
        this.cacheManager = cacheManager;
    }
}
